package com.glory.nicleanrpt

/**
 * @Program: njcleanrpt
 * @Description: 制造报表
 * @Author: ivan
 */
class MakeReportController {

    def dynamicQueryService
    def commonSQLService

    def makeReport() {
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 100
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        def pageSizeList = [10, 20, 50, 100]
        params.docState = params.docState ? Arrays.asList(params.docState) : (params['docState[]'] ? Arrays.asList(params['docState[]']) : '')
        params.wipState = params.wipState ? Arrays.asList(params.wipState) : (params['wipState[]'] ? Arrays.asList(params['wipState[]']) : '')
        params.fahuo = params.fahuo ? Arrays.asList(params.fahuo) : (params['fahuo[]'] ? Arrays.asList(params['fahuo[]']) : '')
        params.stageDesc = params.stageDesc ? Arrays.asList(params.stageDesc) : (params['stageDesc[]'] ? Arrays.asList(params['stageDesc[]']) : '')
        // 状态
        params.SYS_QUERY_NAME = 'makeReportWipState'
        def wipStateList = dynamicQueryService.queryForList(params)
        // 客户名称
        def makeReportKhmc = commonSQLService.customNameList(params)
        // 清洗属性
        params.SYS_QUERY_NAME = 'makeReportQxsx'
        def makeReportQxsx = dynamicQueryService.queryForList(params)
        // 工步
        params.SYS_QUERY_NAME = 'wipStepList'/* makeReportStepDesc */
        def makeReportStepDesc = dynamicQueryService.queryForList(params)
        // 订单状态
        def makeReportDocState = commonSQLService.poStateList(params)
        // 达成状态
        params.SYS_QUERY_NAME = 'makeReportFahuoState'
        def makeReportFahuoState = dynamicQueryService.queryForList(params)
        // 包装
        params.SYS_QUERY_NAME = 'makeReportPackageState'
        def makeReportPackageState = dynamicQueryService.queryForList(params)
        // 工段
//        params.SYS_QUERY_NAME = 'makeReportStageDesc'
//        def makeReportStageDesc = dynamicQueryService.queryForList(params)
        def makeReport = []
        def tableHeadList = []
        def totalCount = 0
        if ('Excel'.equals(params.EXPORT_CONTENT_NAME)) {
            params.SYS_QUERY_NAME = 'makeReport'
            makeReport = dynamicQueryService.queryForList(params)
            if (makeReport.size() > 0) {
                tableHeadList = makeReport[0].keySet()
            }
            params.SYS_QUERY_NAME = 'makeReportCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT
//            totalCount = makeReport.size()
        }
        [
                tableHeadList : tableHeadList, pageSizeList: pageSizeList, pageSize: pageSize, totalCount: totalCount, startno: params.startno ?: '', endno: params.endno ?: '',
                makeReport    : makeReport, ipn: params.ipn ?: '', caseNum: params.caseNum ?: '', ipn: params.ipn ?: '', stepDesc: params.stepDesc ?: '',
                pono          : params.pono ?: '', docId: params.docId ?: '', vpn: params.vpn ?: '', startTime: params.startTime ?: '', endTime: params.endTime ?: '',
                svpn          : params.svpn ?: '', kyh: params.kyh ?: '', state: params.state ?: '', khmc: params.khmc ?: '', qxsx: params.qxsx ?: '', sipn: params.sipn ?: '', fahuo: params.fahuo ?: '', package1: params.package1,
                makeReportKhmc: makeReportKhmc, makeReportDocState: makeReportDocState, wipStateList: wipStateList,
                makeReportQxsx: makeReportQxsx, makeReportStepDesc: makeReportStepDesc, makeReportFahuoState: makeReportFahuoState, makeReportPackageState: makeReportPackageState,
                docState      : params.docState ?: '', /*makeReportStageDesc: makeReportStageDesc,*/ stageDesc: params.stageDesc ?: '', startTime: params.startTime ?: '', endTime: params.endTime ?: '',
                yanchi        : params.yanchi ?: '', naqi: params.naqi ?: '', wipState: params.wipState ?: '',
                affStartTime  : params.affStartTime ?: '',
                affEndTime    : params.affEndTime ?: '', customerLot: params.customerLot ?: ''
        ]
    }
}